<div class="window" style="max-width: 800px; margin: 0 auto 10px auto;">
	<div class="title">Parametrs</div>
	<div class="content">
		<?php echo $form->create('Parametrs', array('url' => '/reports')); ?>
		<table>
			<tr>
				<td style="text-align: center;">Date range</td>
				<td style="text-align: center;">User</td>
				<td style="text-align: center;">Project</td>
			</tr>
			<tr>
				<td>
					<?php echo $form->input('date_start', array(
						'id' => 'date_start',
						'div' => false,
						'label' => false,
						'default' => (date('Y-m-')).'01'
					)); ?>
					-
					<?php echo $form->input('date_end', array(
						'id' => 'date_end',
						'div' => false,
						'label' => false,
						'default' => date('Y-m-d')
					)); ?>
				</td>
				<td>
					<?php echo $form->input('user', array(
						'options' => $users,
						'label' => false,
						'default' => $current_user['User']['id']
					)); ?>
				</td>
				<td>
					<?php echo $form->input('project', array(
						'options' => $projects,
						'label' => false,
						'default' => $current_project['Project']['id']
					)); ?>
				</td>
			</tr>
		</table>
		<?php echo $form->end('Report'); ?>
	</div>
</div>
<div class="window report-window" style="max-width: 800px; margin: 0 auto;">
	<div class="title">Project report<?php if (!empty($times)) : ?>
			"<b><?php echo $projects[$this->data['Parametrs']['project']]; ?></b>"
			for user <b><?php echo $users[$this->data['Parametrs']['user']]; ?></b>,
			over a period from <b><?php echo $this->data['Parametrs']['date_start']; ?></b>
			to <b><?php echo $this->data['Parametrs']['date_end']; ?></b>
		<?php endif;?></div>
	<div class="content">
		<?php if (!empty($times)) : ?>
		<table style="width: 100%">
			<tr>
				<td class="even" style="text-align: center;">Task name <i>- Comment</i></td>
				<td class="even" style="text-align: center;">Date</td>
				<td class="even" style="text-align: center;">Time</td>
			</tr>
			<?php $all_minutes = 0; ?>
			<?php foreach($times as $i => $time) : ?>
			<tr>
				<td class="task-name <?php echo ($i % 2 == 0) ? 'not-even' : 'even'; ?>">
					<a href="/tasks/view/<?php echo $time['Task']['id']; ?>"><div>
						<?php echo $time['Task']['name']; ?>
							
						<?php if (!empty($time['Time']['comment'])) : ?>
							<i>- <?php echo $time['Time']['comment']; ?></i>
						<?php endif; ?>
					</div></a>
				</td>
				<td class="date <?php echo ($i % 2 == 0) ? 'not-even' : 'even'; ?>"><?php echo date('Y-m-d', $time['Time']['finish']*60); ?></td>
				<td class="minutes <?php echo ($i % 2 == 0) ? 'not-even' : 'even'; ?>">
					<?php
						$minutes = $time['Time']['finish'] - $time['Time']['start'] - $time['Time']['pause'];
						$all_minutes += $minutes;
						
						echo $date->minutesToTime($minutes);
					?>
				</td>
			</tr>
			<?php endforeach; ?>
			<tr class="total">
				<td colspan="2" class="even" style="text-align: right; font-weight: bold;">Total</td>
				<td class="even minutes" style="font-weight: bold;">
					<?php echo $date->minutesToTime($all_minutes); ?>
				</td>
			</tr>
		</table>
		<?php else : ?>
			Not found in the range time
		<?php endif; ?>
	</div>
</div>

<script>
	$("#date_start, #date_end").datepicker({ dateFormat: 'yy-mm-dd' });
</script>